package excelgo

import (
	"strconv"
)

func strInt(s string) int {
	if s == "" {
		return 0
	}
	i, err := strconv.Atoi(s)
	if err != nil {
		return 0
	}
	return i
}
func strInt32(s string) int32 {
	if s == "" {
		return 0
	}
	si, err := strconv.ParseInt(s, 10, 32)
	if err != nil {
		return 0
	}
	return int32(si)
}

func strInt64(s string) int64 {
	if s == "" {
		return 0
	}
	si, err := strconv.ParseInt(s, 10, 64)
	if err != nil {
		return 0
	}
	return si
}

func strFloat64(s string) float64 {
	if s == "" {
		return 0
	}
	f, err := strconv.ParseFloat(s, 64)
	if err != nil {
		return 0
	}
	return f
}

func strBool(s any) bool {
	if s == nil {
		return false
	} else {
		switch s.(type) {
		case bool:
			b := s.(bool)
			return b
		case string:
			s2 := s.(string)
			if s2 == "" {
				return false
			} else {
				return true
			}
		default:
			return false
		}
	}
}
